//
//  AirObjectUtility.h
//  AirOtaGraghics
//
//  Created by hao peng on 13-9-23.
//  Copyright (c) 2013年 hao peng.
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//

#ifndef __AirOtaGraghics__AirObjectUtility__
#define __AirOtaGraghics__AirObjectUtility__

#include <iostream>
namespace AirCpp {
    
template <class T>
struct AirObjectMutilyThreaded
{
    void Lockguard(T* &ptr){
        printf("Lockguard!!!!");
    };
};

template <class T>
struct AirObjectSingleThreaded
{
    void Lockguard(T* &ptr){
    };
};

template <class T>
class AirObjectRetainCount{
public:
    T *p_t;
public:
    AirObjectRetainCount(){ p_t = new T(); }
    
    AirObjectRetainCount(T *_t){
        p_t = _t;
        _t->retain();
    }
    ~AirObjectRetainCount(){ p_t = NULL; }
    
    
    T& operator *(){
        return *p_t;
    }
    T* operator ->(void){
        return p_t;
    }
    
    AirObjectRetainCount *operator=(T *_t)
    {
        _t->retain();
        if (NULL != p_t) {
            p_t->release();
        }
        p_t = _t;
        return this;
    }
    
    AirObjectRetainCount &operator=(T &_t)
    {
        
        _t.retain();
        if (NULL != p_t) {
            p_t->release();
        }
        p_t = &_t;
        return *this;
    }
    AirObjectRetainCount &operator=(AirObjectRetainCount &foo)
    {
        (&foo)->p_t->retain();
        if (NULL != p_t) {
            p_t->release();
        }
        p_t = (&foo)->p_t;
        return *this;
    }
};
}
#endif /* defined(__AirOtaGraghics__AirObjectUtility__) */
